/**
 * 
 */
package cq.com.cn.utils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.sql.DataSource;

import com.mchange.v2.c3p0.ComboPooledDataSource;

/**
 * @author summer
 * 连接池工具类
 */
public class C3p0Utils {

	public static DataSource dataSource=new ComboPooledDataSource();
	
	/**
	 * @return 返回数据库连接对象
	 * @throws ClassNotFoundException
	 * @throws SQLException
	 */
	public static Connection getConnection() throws SQLException{
			return dataSource.getConnection();
	}
	//关闭所有资源
	public static void release( Connection con,PreparedStatement ps,ResultSet rs){
		if(null!=con){
			try {
				con.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if(null!=ps){
			try {
				ps.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		if(rs!=null){
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}
	
}
